package movieGandalf.dataObjects;

//import java.io.File;
import java.math.BigInteger;
import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.*;

public class MovieImp implements Movie{
	
	private BigInteger id;
	private String name;
	private String imdbName;
	private int year;
	private int length;
	private Country country;
	private Language language;
	private BigInteger directorID;
	private Boolean isColor;
	private MPAARating mpaaRating;
	private Float MSLRating;
	
	/*constructors*/

	public MovieImp(BigInteger id, String name, String imdbName, int year){
		this.id = id;
		this.name = name;
		this.imdbName = imdbName;
		this.year = year;
	}
	
	public MovieImp(BigInteger id, String name, String imdbName, int year,int length,
					Integer countryID, Integer languageID, BigInteger directorID,
					Boolean isColor, Integer mpaaRatingID, Float mslr){
		this.id = id;
		this.name = name;
		this.imdbName = imdbName;
		this.year = year;
		this.length = length;
		this.country = new CountryImp(countryID,null);
		this.language = new LanguageImp(languageID,null);
		this.directorID = directorID;
		this.isColor = isColor;
		this.mpaaRating = new MPAARatingImp(mpaaRatingID,null);
		this.MSLRating = mslr;
	}
	
	public MovieImp(BigInteger id, String name, String imdbName, int year,int length,
			Country country, Language language, BigInteger directorID,
			Boolean isColor, MPAARating mpaaRating, Float mslr){
		this.id = id;
		this.name = name;
		this.imdbName = imdbName;
		this.year = year;
		this.length = length;
		this.country = country;
		this.language = language;
		this.directorID = directorID;
		this.isColor = isColor;
		this.mpaaRating = mpaaRating;
		this.MSLRating = mslr;
	}

	/*getters*/
	
	public BigInteger getID(){
		return id;
	}
	
	public String getName(){
		return name;
	}
	
	public String getImdbName(){
		return imdbName;
	}
	
	public int getYear(){
		return year;
	}
	
	public int getLength(){
		return length;
	}
	
	public Integer getCountryID() {
		return country.getID();
	}
	
	public Country getCountry(){
		return country;
	}

	public String getCountryName(){
		if (country == null)
			return null;
		
		return country.getCountry();
	}
	
	public Integer getLanguageID(){
		if (language == null)
			return null;
		
		return language.getID();
	}

	public String getLanguageName(){
		if (language == null)
			return null;
		
		return language.getLanguage();
	}
	
	public Language getLanguage(){
		return language;
	}
	
	public BigInteger getDirectorID(){
		return directorID;
	}

	
	public boolean isColor() {
		return isColor;
	}

	
	public MPAARating getMPAARating(){
		return mpaaRating;
	}
	
	public String getMPAARatingName(){
		if (mpaaRating == null)
			return null;
		
		return mpaaRating.getMPAARating();
	}
	
	public Integer getMPAARatingID(){
		if (mpaaRating == null)
			return null;
		
		return mpaaRating.getID();
	}
	
	public Float getOurRating(){
		return this.MSLRating;
	}

	
	public List<Role> getActorList(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getActorsList(conn, this.getID());
	}

	
	public List<Genre> getGenre(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getGenres(conn, this.getID());
	}

	public Director getDirector(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getDirector(conn, this.getDirectorID());
	}

	public List<Genre> getGenres(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getGenres(conn, this.getID());
	}

	public List<Integer> getGenreIDs(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getGenreIDs(conn, this.getID());
	}
	
	public String getDescription(){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getMovieDescription(conn, this.getID());
	}
	
	/*setters*/
	
	public void setID(BigInteger id){
		this.id = id;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public void setImdbName(String imdbName){
		this.imdbName = imdbName;
	}
	
	public void setYear(int year){
		this.year = year;
	}
	
	public void setLength(int length){
		this.length=length;
	}
	
	public void setCountry(Country country){
		this.country = country;
	}
	
	public void setLanguage(Language language){
		this.language = language;
	}
	
	public void setDirectorID(BigInteger directorID){
		this.directorID = directorID;
	}

	public void setColor(boolean isColor) {
		this.isColor= isColor;
	}

	public void setMPAARating(MPAARating mpaaRating) {
		this.mpaaRating = mpaaRating;
	}

	public void setOurRating(Float ourRating) {
		this.MSLRating = ourRating;
	}
	
	public boolean addGenre(Integer genreID){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.addMovieGenre(conn, id, genreID);
	}
	
	public boolean setGenre(LinkedList<Genre> genre) {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.setGenre(conn, id, genre);
	}

	public boolean setDescription(String description) {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateDescription(conn, id, description);
	}

	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateMovie(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}
	
}
